using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ShivamEMR.Model.Domain.CompanyDomain;
using ShivamEMR.Model.DataInterfaces.CompanyDataInterf;
using ShivamEMR.Model;

//using ShivamEMR.Web.Areas.Company.Models;

namespace ShivamEMR.Web.Areas.Company.Controllers
{   
    public class ScheduleController : Controller
    {
        private readonly IScheduleSatatusRepository schedulestatusRepository;
		private readonly IScheduleRepository scheduleRepository;

		// If you are using Dependency Injection, you can delete the following constructor
        public ScheduleController() 
        {
            schedulestatusRepository = Registry.RepositoryFactory.GetScheduleStatusRepository();
            scheduleRepository = Registry.RepositoryFactory.GetScheduleRepository();
        }

        public ScheduleController(IScheduleSatatusRepository schedulestatusRepository, IScheduleRepository scheduleRepository)
        {
			this.schedulestatusRepository = schedulestatusRepository;
			this.scheduleRepository = scheduleRepository;
        }

        //
        // GET: /Schedule/

        public ViewResult Index()
        {
            return View(scheduleRepository.All);
        }

        //
        // GET: /Schedule/Details/5

        public ViewResult Details(System.Guid id)
        {
            return View(scheduleRepository.Find(id));
        }

        //
        // GET: /Schedule/Create

        public ActionResult Create()
        {
			ViewBag.PossibleScheduleStatus = schedulestatusRepository.All;
            var shcedule = new Schedule() { StartTime=DateTime.Now, EndTime=DateTime.Now };
            return View();
        } 

        //
        // POST: /Schedule/Create

        [HttpPost]
        public ActionResult Create(Schedule schedule)
        {
            if (ModelState.IsValid) {
                scheduleRepository.Create(schedule);
                scheduleRepository.Save();
                return RedirectToAction("Index");
            } else {
				ViewBag.PossibleScheduleStatus = schedulestatusRepository.All;
				return View();
			}
        }
        
        //
        // GET: /Schedule/Edit/5
 
        public ActionResult Edit(System.Guid id)
        {
			ViewBag.PossibleScheduleStatus = schedulestatusRepository.All;
             return View(scheduleRepository.Find(id));
        }

        //
        // POST: /Schedule/Edit/5

        [HttpPost]
        public ActionResult Edit(Schedule schedule)
        {
            if (ModelState.IsValid) {
                scheduleRepository.Update(schedule);
                scheduleRepository.Save();
                return RedirectToAction("Index");
            } else {
				ViewBag.PossibleScheduleStatus = schedulestatusRepository.All;
				return View();
			}
        }

        //
        // GET: /Schedule/Delete/5
 
        public ActionResult Delete(System.Guid id)
        {
            return View(scheduleRepository.Find(id));
        }

        //
        // POST: /Schedule/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(System.Guid id)
        {
            var sr = scheduleRepository.Find(id);
            scheduleRepository.Delete(sr);
            scheduleRepository.Save();

            return RedirectToAction("Index");
        }
    }
}

